package com.liming;

import java.util.HashMap;
import java.util.Map;
import java.util.Set;
import java.util.function.BiConsumer;
import java.util.function.Consumer;

public class MapDemo {
    public static void main(String[] args) {
        tes0();
        System.out.println("------------------");
        tes1();
        System.out.println("------------------");
        tes2();
        System.out.println("------------------");
        tes3();
    }
    public static void tes3() {
        Map<String, Double> map = new HashMap<>();
        map.put("肖博文", 99.0);
        map.put("萧炎", 98.0);
        map.put("唐三", 97.0);
        map.put("小舞", 96.0);
        map.put("荒天帝", 95.0);
        //遍历
        map.forEach(new BiConsumer<String, Double>(){
            @Override
            public void accept(String key, Double value) {
                System.out.println(key + " : " + value);
            }
        } );
        map.forEach((key,value) -> System.out.println(key + " : " + value));
    }
    public static void tes2() {
        Map<String, Double> map = new HashMap<>();
        map.put("肖博文", 99.0);
        map.put("萧炎", 98.0);
        map.put("唐三", 97.0);
        map.put("小舞", 96.0);
        map.put("荒天帝", 95.0);
        //遍历
        Set<Map.Entry<String, Double>> entrySet = map.entrySet();
        for (Map.Entry<String, Double> entry : entrySet) {
            //获取键值对
            String key = entry.getKey();
            Double value = entry.getValue();
            System.out.println(key + " : " + value);
        }
    }
    public static void tes1() {
        Map<String, Double> map = new HashMap<>();
        map.put("肖博文", 99.0);
        map.put("萧炎", 98.0);
        map.put("唐三", 97.0);
        map.put("小舞", 96.0);
        map.put("荒天帝", 95.0);
        Set<String> keySet = map.keySet();
        for (String key : keySet) {
            Double value = map.get(key);
            System.out.println(key + " : " + value);
        }
    }
    public static void tes0() {
        Map<String, Double> map = new HashMap<>();
        map.put("肖博文", 99.0);
        map.put("萧炎", 98.0);
        map.put("唐三", 97.0);
        map.put("小舞", 96.0);
        map.put("荒天帝", 95.0);
        System.out.println(map);
        System.out.println("------------------");
        map.remove("肖博文",99.0);
        System.out.println(map);
        //判断集合是否包含指定的键或值
        boolean b1 = map.containsKey("唐三");
        System.out.println(b1);
        boolean b2 = map.containsValue(99.0);
        //判断集合是否为空
        boolean empty = map.isEmpty();
        System.out.println(empty);
        //获取集合的大小
        int size = map.size();
        System.out.println(size);
        Set<String> keySet = map.keySet();
    }
}
